package com.vma.jifu.controller;

import com.vma.jifu.bizModel.model.Address;
import com.vma.jifu.service.AddressService;
import com.vma.jifu.service.impl.AddressServiceImpl;

/**
 * Created by chenzui on 2017/6/23.
 */
public class AddressController extends BaseController {

    private AddressService addressService = new AddressServiceImpl();


    public void add(){
        Integer userId = getParaToInt("userId");
        String province = getPara("province");
        String city = getPara("city");
        String area = getPara("area");
        String detail = getPara("detail");
        String phone = getPara("phone");
        String receiver = getPara("receiver");
        Integer isDefault = getParaToInt("isDefault");
        addressService.addAddress(userId,province,city,area,detail,isDefault,phone,receiver);
        renderRes("success");
    }


    public void delete(){
        Integer id = getParaToInt("id");
        Integer userId = getParaToInt("userId");
        addressService.delete(id,userId);
        renderRes("success");
    }

    public void update(){
        Integer id = getParaToInt("id");
        Integer userId = getParaToInt("userId");
        String province = getPara("province");
        String city = getPara("city");
        String area = getPara("area");
        String detail = getPara("detail");
        String phone = getPara("phone");
        String receiver = getPara("receiver");
        Integer isDefault = getParaToInt("isDefault");
        addressService.updateAddress(id,userId,province,city,area,detail,isDefault,phone,receiver);
        renderRes("success");
    }

    public void qryAddressListByUser(){
        Integer userId = getParaToInt("userId");
        renderRes(addressService.qryAddressListByUser(userId));
    }

    public void qryDefaultAddressByUser(){
        Integer userId = getParaToInt("userId");
        renderRes(addressService.qryDefaultAddressByUser(userId));
    }

    public void getAddressById(){
        Integer addressId = getParaToInt("id");
        renderRes(Address.dao.findById(addressId));
    }
}
